{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "state = [-0.00417787 -0.17877367 -0.04819508  0.29581413]; reward = 1.0\n",
      "state = [-0.00775334  0.01700103 -0.0422788  -0.01167082]; reward = 1.0\n",
      "state = [-0.00741332 -0.17748988 -0.04251221  0.2673786 ]; reward = 1.0\n",
      "state = [-0.01096312 -0.37198013 -0.03716464  0.54635555]; reward = 1.0\n",
      "state = [-0.01840272 -0.56656075 -0.02623753  0.82710105]; reward = 1.0\n",
      "state = [-0.02973394 -0.37109005 -0.00969551  0.52628297]; reward = 1.0\n",
      "state = [-0.03715574 -0.17583302  0.00083015  0.23056075]; reward = 1.0\n",
      "state = [-0.0406724   0.01927706  0.00544136 -0.06186021]; reward = 1.0\n",
      "state = [-0.04028686  0.21432057  0.00420416 -0.35282138]; reward = 1.0\n",
      "state = [-0.03600045  0.01913909 -0.00285227 -0.05881574]; reward = 1.0\n",
      "state = [-0.03561766  0.21430182 -0.00402858 -0.3523972 ]; reward = 1.0\n",
      "state = [-0.03133163  0.40948084 -0.01107653 -0.64634776]; reward = 1.0\n",
      "state = [-0.02314201  0.21451496 -0.02400348 -0.3571733 ]; reward = 1.0\n",
      "state = [-0.01885171  0.4099698  -0.03114695 -0.6573275 ]; reward = 1.0\n",
      "state = [-0.01065232  0.21529494 -0.0442935  -0.3746125 ]; reward = 1.0\n",
      "state = [-0.00634642  0.02082922 -0.05178574 -0.09621807]; reward = 1.0\n",
      "state = [-0.00592983 -0.17351374 -0.05371011  0.17968737]; reward = 1.0\n",
      "state = [-0.00940011  0.02233402 -0.05011636 -0.12944382]; reward = 1.0\n",
      "state = [-0.00895343  0.21813674 -0.05270524 -0.43750718]; reward = 1.0\n"
     ]
    },
    {
     "ename": "",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31mThe Kernel crashed while executing code in the the current cell or a previous cell. Please review the code in the cell(s) to identify a possible cause of the failure. Click <a href='https://aka.ms/vscodeJupyterKernelCrash'>here</a> for more info. View Jupyter <a href='command:jupyter.viewOutput'>log</a> for further details."
     ]
    }
   ],
   "source": [
    "import gym\n",
    "import time\n",
    "# 生成环境\n",
    "env = gym.make('CartPole-v1')\n",
    "# 环境初始化\n",
    "state = env.reset()\n",
    "# 循环交互\n",
    "while True:\n",
    "    # 渲染画面\n",
    "    env.render()\n",
    "    # 从动作空间随机获取一个动作\n",
    "    action = env.action_space.sample()\n",
    "    # agent与环境进行一步交互\n",
    "    state, reward, done, info = env.step(action)\n",
    "    # state, reward= env.step(action)\n",
    "    # ret= env.step(action)\n",
    "    # print('ret:', ret)\n",
    "    # done= True\n",
    "    print('state = {0}; reward = {1}'.format(state, reward))\n",
    "    # 判断当前episode 是否完成\n",
    "    if done:\n",
    "        print('done')\n",
    "        break\n",
    "    time.sleep(1)\n",
    "# 环境结束\n",
    "env.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "model_scope",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.19"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
